<?php

class Zend_View_Helper_Formpersonalizado extends Zend_View_Helper_Abstract
{

    public function formPersonalizado($cdForm, $erros, $frmValues)
    {
        $tableForm = ZC_Model::factory(ZC_Model::TABLE_CAMPO_PERSONALIZADO_FORM);
        $tableSub = ZC_Model::factory(ZC_Model::TABLE_CAMPO_PERSONALIZADO_SUBFORM);
        $tableSubCp = ZC_Model::factory(ZC_Model::TABLE_CAMPO_PERSONALIZADO_SUBFORM_CAMPOS);
        $tableCpPe = ZC_Model::factory(ZC_Model::TABLE_CAMPO_PERSONALIZADO);

        $campos = $tableForm->getDefaultAdapter()
                ->select()
                ->from(array('f' => $tableForm->getTableName()), array('f.cdForm'))
                ->joinInner(array('s' => $tableSub->getTableName()), 's.cdForm = f.cdForm', array('s.stSubForm', 's.nrOrdem', 's.cdTipo as cdTipoSubForm'))
                ->joinInner(array('c' => $tableSubCp->getTableName()), 'c.cdSubform = s.cdSubform')
                ->joinLeft(array('cp' => $tableCpPe->getTableName()), 'cp.cdCampo = c.cdCampo and c.inFixo = 0', array('cp.cdTipo', 'cp.inObrigatorio', 'cp.stConfig as stConfigCp'))
                ->where('f.cdForm = '.$cdForm)
                ->order(array('s.nrOrdem', 'c.nrOrdem'))
                ->query()
                ->fetchAll()
        ;
        
        $paginaModel = new Model_DbTable_Tbpagina();
        $paginaRow = $paginaModel->findRow(40);
        $texto = ZC_Bbcode::getInstance()->parseHtml($paginaRow->stconteudo);

        echo $this->view->partial('partial/formpersonalizado.phtml', array(
            'campos' => $campos,
            'erros' => $erros,
            'frmValues' => $frmValues,
            'txtTermos' => $texto
        ));
    }

}
